<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path;
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script type="text/javascript" src="<%=basePath %>/resource/js/common-css-js.js"></script>
<title>大旗科技有限公司</title>
<style>
	body {
		padding: 10px;
	}
	
	.tools {
		width: 100%;
	    background: #f1f1f1;
	    border: 1px solid #CCB;
	    border-bottom: 0px;
	    padding: 0 5px;
	    display: flex;
	}
	
	.tools-item {
		padding: 5px 10px;
	    font-weight: bold;
	    color: #999;
	    cursor: pointer;
	}

	.layui-icon {
		font-size: 15px;
	}
	
	.tools-item:hover {
		color: black;
	}
	
</style>
</head>
<body>

	<div class="tools">
	 	<div class="tools-item tools-item-submit">
	 		<i class="layui-icon layui-icon-upload-circle"></i>   
	 	</div>
	 	<div class="tools-item tools-item-clean">
	 		<i class="layui-icon layui-icon-fonts-clear"></i>   
	 	</div>
	</div>
	 
	<div id="editor">
    </div>
    
    <script type="text/javascript" src="<%=basePath %>/resource/js/wangEditor.min.js"></script>
    <script type="text/javascript">
	    //获取被选中的行的对象
	    var selectedRow = parent.cTable.bootstrapTable('getSelections');
        //获取到富文本编辑器对象
    	var E = window.wangEditor
    	//获取到展示的dom区域
        var editor = new E('#editor')
        //创建富文本编辑器
        editor.create()
        //回现数据
        editor.txt.html(selectedRow[0].noticeContent);
       	
        //提交数据
        $(".tools-item-submit").click(function(){
        	//获取到文本的内容
        	var content = editor.txt.html();
        	
        	if(content == selectedRow[0].noticeContent){
        		//内容不变,但是点击了提交的情况
        		fixedAlert('更新公告成功!',1,true);
        	}else{
        		//内容发生变化
            	layer.prompt({title:'发布主题',value:selectedRow[0].noticeTheme},function(val, index){
            		
            		//将新输入的值赋值到,请求体对象中
            		selectedRow[0].noticeTheme = val;
            		selectedRow[0].noticeContent = content;
            		
            		//发送同步ajax请求
            		$.ajax({
            		   url: path + "/notice",
           			   type: "PUT",
           			   async: false,
           			   data: selectedRow[0],
    	       		   beforeSend: function () {
    	     			   layerIndex = layer.load(2);
    	               },
    	               statusCode : {
    	            	   200: function(){
    	            		   fixedAlert('更新公告成功!',1,true);
    	            	   },
    	            	   400: function(){
    	            		   fixedAlert('更新公告失败!',2);
    	            	   },
    	            	   500: function(){
    	            		   fixedAlert('服务器繁忙!',0);
    	            	   }
    	               },
    	               complete: function(XMLHttpRequest, textStatus){
    	            	   layer.close(layerIndex);
    	               }
           			});
            	});
        	}
        	
        });
        
        //清空内容
        $(".tools-item-clean").click(function(){
        	$("div[contenteditable='true']").children().remove();
        });
    </script>
</body>
</html>